cmake_minimum_required(VERSION 3.0.2)

project(edgeai_tidl_examples)

exec_program(pkg-config ARGS --cflags glib-2.0 OUTPUT_VARIABLE GLIB_FLAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GLIB_FLAGS}")

if(NOT DEFINED CMAKE_SYSTEM_PROCESSOR OR CMAKE_SYSTEM_PROCESSOR STREQUAL "")
  message(WARNING "CMAKE_SYSTEM_PROCESSOR is not defined. Perhaps CMake toolchain is broken")
endif()

message(STATUS "Detected processor: ${CMAKE_SYSTEM_PROCESSOR}")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
  set(HOST_CPU x86)
  if(NOT DEFINED ENV{SOC} OR ENV{SOC} STREQUAL "" )
    message(FATAL_ERROR "SOC not specicfied, please export SOC variable")
  else()
    set(TARGET_DEVICE $ENV{SOC})
    message(STATUS "TARGET_DEVICE setting to: ${TARGET_DEVICE}")
  endif()
  if(NOT DEFINED TARGET_DEVICE)
    message(FATAL_ERROR "SOC not specicfied, please export SOC variable")
  endif()
  if(NOT DEFINED TARGET_CPU)
    set(TARGET_CPU x86)
    message(STATUS "TARGET_CPU not specicfied using ${TARGET_CPU} ")
  endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*|arm64.*|ARM64.*)")
  set(HOST_CPU arm)
  if(NOT DEFINED ENV{SOC} OR ENV{SOC} STREQUAL "" )
    message(FATAL_ERROR "SOC not specicfied, please export SOC variable")
  else()
    set(TARGET_DEVICE $ENV{SOC})
    message(STATUS "TARGET_DEVICE setting to: ${TARGET_DEVICE}")
  endif()  
  if(NOT DEFINED TARGET_DEVICE)
    message(FATAL_ERROR "SOC not specicfied, please export SOC variable")
    endif()
    if(NOT DEFINED TARGET_CPU)
      set(TARGET_CPU arm)
      message(STATUS "TARGET_CPU not specicfied using ${TARGET_CPU} ")
    endif()
endif()

add_subdirectory(osrt_cpp/post_process)
add_subdirectory(osrt_cpp/pre_process)
add_subdirectory(osrt_cpp/utils)
add_subdirectory(osrt_cpp/tfl)
if( ${TARGET_DEVICE} STREQUAL "am62")
    message(STATUS "configured device :AM62 disabling advanced and dlr examples")
else()
    add_subdirectory(osrt_cpp/advanced_examples/tfl)
    add_subdirectory(osrt_cpp/advanced_examples/ort)
    add_subdirectory(osrt_cpp/advanced_examples/utils)
    add_subdirectory(tidlrt_cpp)
    add_subdirectory(osrt_cpp/dlr)
endif()
add_subdirectory(osrt_cpp/ort)
